﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Services;
using Sobiens.Web.Controls.ItemSelector.Samples.BLL;
using System.Text;

namespace Sobiens.Web.Controls.ItemSelector.Samples
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Selected Items:");
            foreach (Item item in SBSItemSelector.SelectedItems)
            {
                sb.Append(string.Format("{0},", item.Text));
            }
            SelectedItemsLabel1.Text = sb.ToString();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Selected Items:");
            foreach (Item item in SBSItemSelector.SelectedItems)
            {
                sb.Append(string.Format("{0},", item.Text));
            }
            SelectedItemsLabel2.Text = sb.ToString();
        }

        [WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        //public ListItemCollection GetCompletionList(string prefixText, int count, string contextKey)
        public static ListItemCollection GetCompletionList(string prefixText)
        {
            ListItemCollection items = new ListItemCollection();
            DataSet ds = ItemsManager.SearchItems(prefixText);
            foreach(DataRow row in ds.Tables[0].Rows)
            {
                items.Add(new ListItem(row["ItemName"].ToString(), row["Item_ID"].ToString()));
            }
            return items;
        }

    }
}